import heapq
import itertools
from collections import Counter

prices = {
    "AAPL":191.88,
    "GOOG":1186.1,
    "IBM":148.2,
    "ORCL":48.44
}


prices = {key : value for key, value in prices.items() if value > 100}
print(prices)

prices = {key : value for key, value in prices.items() if value < 200}
print(prices)


names = ["张三", "李四", "王五", "杨六","朱七", "冯八"]
courses= ["语文", "数学", "英语"]


#scores = [[None] * len(courses) for _ in range(len(names))]
#for row, name in enumerate(names):
#    for col, course in enumerate(courses):
#        scores[row][col] = float(input(f'请输入{name}的{course}成绩: '))
#        print(scores)

#### heapq模块（堆排序）

list1 = [34, 25, 12, 99, 87, 63, 58, 78, 88, 92]
list2 = [
    {'name': 'IBM', 'shares': 100, 'price': 91.1},
    {'name': 'AAPL', 'shares': 50, 'price': 543.22},
    {'name': 'FB', 'shares': 200, 'price': 21.09},
    {'name': 'HPQ', 'shares': 35, 'price': 31.75},
    {'name': 'YHOO', 'shares': 45, 'price': 16.35},
    {'name': 'ACME', 'shares': 75, 'price': 115.65}
]

#找出最大的3个元素
print(heapq.nlargest(3, list1))
print(heapq.nsmallest(3, list1))
print(heapq.nlargest(3, list2, key=lambda x:x['price']))
print(heapq.nsmallest(3, list2, key=lambda x:x['shares']))


## itertools模块

#permutations, ABCD的全排列
permutations = itertools.permutations("ABCD")
for perm in permutations:
    print(perm)

## 产生ABCDE的五选三组合
itertools.combinations("ABCDE", 3)

## 产生笛卡尔积
itertools.product("ABCDE",  "123")


words = ["look", "into", "my", "eyes", "look"]
counter = Counter(words)
print(counter.most_common(3))
